package com.yhy.wxzn.wcs.wcsWmsCommunication.bean;


import com.yhy.wxzn.common.enums.WcsDeviceTypeEnums;
import com.yhy.wxzn.common.utils.SpringUtil;
import com.yhy.wxzn.wcs.SystemInit;
import com.yhy.wxzn.wcs.device.plc.bean.HoistPlc;
import com.yhy.wxzn.wcs.device.plc.bean.XJPHoistPlc;
import com.yhy.wxzn.wcs.device.rgv.bean.Coord;
import com.yhy.wxzn.wcs.device.rgv.bean.FourWayRgv;
import com.yhy.wxzn.wcs.device.rgv.bean.Lifter;
import com.yhy.wxzn.wcs.entity.WcsDeviceInfo;
import com.yhy.wxzn.wcs.service.impl.WcsMapInfoServiceImpl;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

import static com.yhy.wxzn.wcs.SystemInit.liferPlcMap;

@Getter
@Setter
public class ReturnMsgDevice  {
    private Integer deviceNo;
    private Integer deviceType;
    private String location;
    private Integer deviceStatus;
    private String deviceInfo;


    public static WcsDeviceTypeEnums parseDeviceType(int deviceType){
        if (deviceType == 1) return WcsDeviceTypeEnums.FWV;
        if (deviceType == 2) return WcsDeviceTypeEnums.ELV;
        throw new RuntimeException("未知类型");
    }


    public static int parseDeviceType(WcsDeviceTypeEnums deviceTypeEnums){
        if (deviceTypeEnums == WcsDeviceTypeEnums.FWV) return 1;
        if (deviceTypeEnums == WcsDeviceTypeEnums.ELV) return 2;
        throw new RuntimeException("未知类型");
    }


    public static void buildRgvInfo(List<ReturnMsgDevice> devices, WcsDeviceInfo wcsDeviceInfo){
        ReturnMsgDevice rmd = new ReturnMsgDevice();
        devices.add(rmd);

        rmd.setDeviceNo(wcsDeviceInfo.getId());
        rmd.setDeviceType(parseDeviceType(WcsDeviceTypeEnums.parseWcsDeviceTypeEnums(wcsDeviceInfo.getDeviceType())));
        rmd.setLocation(wcsDeviceInfo.getLocation());
        FourWayRgv rgv = SystemInit.fourWayRgvMap.get(wcsDeviceInfo.getId());
        rmd.setDeviceStatus(rgv.getRgvStatus().getRgvStatus());


    }

    public static void buildLifterInfo(List<ReturnMsgDevice> devices, WcsDeviceInfo wcsDeviceInfo) {
        ReturnMsgDevice rmd = new ReturnMsgDevice();
        devices.add(rmd);

        rmd.setDeviceNo(wcsDeviceInfo.getId());
        rmd.setDeviceType(parseDeviceType(WcsDeviceTypeEnums.parseWcsDeviceTypeEnums(wcsDeviceInfo.getDeviceType())));

        XJPHoistPlc hoistPlc = liferPlcMap.get(wcsDeviceInfo.getId());
        int floor = hoistPlc.getLayer();
        String location = wcsDeviceInfo.getLocation();
        Coord coord = new Coord(Lifter.parseLifter(location));
        coord.setZ(floor);
        rmd.setLocation(coord.toString());
        rmd.setDeviceStatus(0);
    }
}
